package com.huixuebao.after.util;


import com.huixuebao.common.bean.ApiResult;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ocr.v20181119.OcrClient;
import com.tencentcloudapi.ocr.v20181119.models.BizLicenseOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.BizLicenseOCRResponse;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BizLicenseOCR {

    public static String getLicenseOCR(String imagePath){
        String result = "";
        try{

            Credential cred = new Credential("AKIDVnTSBlMuCF2lJaEQxEFza4TimbQ6lz3s", "lHZbMp1pOfhfQ6QVJqGUTBd0FI4mNimc");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);

            BizLicenseOCRRequest req = new BizLicenseOCRRequest();
            req.setImageUrl(imagePath);
            //req.setImageBase64(imageBase);

            BizLicenseOCRResponse resp = client.BizLicenseOCR(req);
            result = BizLicenseOCRResponse.toJsonString(resp);
            log.info("OCR获取企业信息成功！！");
        } catch (TencentCloudSDKException e) {
            log.info("OCR获取企业信息失败,{}",e);
        }
        return result;
    }
}
